#include "stdafx.h"

const void UnitList::init_list(){
	vector<QString> u;
	vector<double> c;
	//pressure;
	u.push_back("Pa");	 c.push_back(1);
	u.push_back("kPa");	 c.push_back(1e3);
	u.push_back("MPa");	 c.push_back(1e6);
	u.push_back("atm");	 c.push_back(101325);
	u.push_back("bar");	 c.push_back(1e5);
	u.push_back("psi");  c.push_back(6894.76);
	unitMatrix.push_back(u);   coeffMatrix.push_back(c);
	//flow
	u.clear(); c.clear(); 
	u.push_back("m3/h");    c.push_back(1);
	u.push_back("m3/s");   c.push_back(2.777777777777778e-4);
	u.push_back("m3/m");   c.push_back(0.0166666666666667);
	u.push_back("m3/d");   c.push_back(60);
	unitMatrix.push_back(u);   coeffMatrix.push_back(c);
	//distance
	u.clear(); c.clear(); 
	u.push_back("m");    c.push_back(1);
	u.push_back("cm");   c.push_back(1e-2);
	u.push_back("mm");   c.push_back(1e-3);
	u.push_back("km");   c.push_back(1e3);
	u.push_back("ft");   c.push_back(0.305);
	unitMatrix.push_back(u);   coeffMatrix.push_back(c);
	//time
	u.clear(); c.clear(); 
	u.push_back("s");    c.push_back(1);
	u.push_back("M");    c.push_back(60);
	u.push_back("h");    c.push_back(3600);
	u.push_back("d");    c.push_back(86400);
	unitMatrix.push_back(u);   coeffMatrix.push_back(c);
	//density
	u.clear(); c.clear(); 
	u.push_back("kg/m3"); c.push_back(1);
	u.push_back("g/cm3"); c.push_back(1e3);
	unitMatrix.push_back(u);   coeffMatrix.push_back(c);
	//viscosity
	u.clear(); c.clear(); 
	u.push_back("CP");     c.push_back(1);
	u.push_back("P");      c.push_back(1e2);
	u.push_back("kg/m-h"); c.push_back(0.277777777778);
	u.push_back("kg/m-s"); c.push_back(1e3);
	u.push_back("Pa-s");   c.push_back(1e3);
	unitMatrix.push_back(u);   coeffMatrix.push_back(c);
    //speed;
    u.clear(); c.clear(); 
    u.push_back("km/h");	 c.push_back(1);
    unitMatrix.push_back(u);   coeffMatrix.push_back(c);
	//-
	u.clear(); c.clear(); 
	u.push_back("-");   c.push_back(1);
	u.push_back("%");   c.push_back(100);
	unitMatrix.push_back(u);   coeffMatrix.push_back(c);
	//-
	u.clear(); c.clear(); 
	u.push_back("");   c.push_back(1);
	unitMatrix.push_back(u);   coeffMatrix.push_back(c);
}

QStringList UnitList::getUnitList(QString unit){
	QStringList list;
	for(int i = 0; i < unitMatrix.size(); i++)
		for(int j = 0; j < unitMatrix[i].size(); j++)
			if(unitMatrix[i][j] == unit){
				for(int k = 0; k < unitMatrix[i].size(); k++)
					list.append(unitMatrix[i][k]);
				break;
			}
	if (!list.count()) list.append(unit);
	return list;
}